package it.rikesh.aip2011.client.component;

import it.rikesh.aip2011.client.service.HomeService;
import it.rikesh.aip2011.client.service.HomeServiceAsync;

import java.util.logging.Logger;

import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.Text;
import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.maps.client.MapWidget;
import com.google.gwt.maps.client.geom.LatLng;
import com.google.gwt.maps.client.overlay.Marker;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.DockLayoutPanel;
import com.google.gwt.user.client.ui.Frame;
import com.google.gwt.user.client.ui.HTML;

/**
 * Classe che implementa la pagina "Dove siamo" del sito. Si occupa di ricavare dal datastore tutte le informazioni necessarie.
 * @author  RN
 */
public class AreaLayout extends LayoutContainer{
    private static final Logger log = Logger.getLogger(HomeLayout.class.getName());
    private static HomeServiceAsync homeService = GWT.create(HomeService.class);
   
    private Text name;
    private HTML frame;
    private Text txt;
    LayoutContainer c;
    
    public AreaLayout(){
        init();
        getInfoHome();
        addComponent();
    }
    
    /**
     * Inizializzo le variabili
     */
    public void init(){
        frame = new HTML("<center><iframe src='http://maps.google.it/maps?f=q&amp;source=s_q&amp;hl=it&amp;geocode=&amp;q=Alagna+Valsesia&amp;aq=0&amp;sll=41.442726,12.392578&amp;sspn=32.591286,35.595703&amp;ie=UTF8&amp;hq=&amp;hnear=Alagna+Valsesia+Vercelli,+Piemonte&amp;ll=45.801999,8.12851&amp;spn=0.191475,0.515671&amp;z=11&amp;iwloc=0&amp;output=embed' style='width: 80%; height: 350px; '></iframe></center>");
        
        name=new Text("L'AREA");
        name.setStyleAttribute("color", "red");
        name.setStyleAttribute("text-align", "center");
        name.setStyleAttribute("font-weight", "bold");
        name.setStyleAttribute("font-size", "35px");
        name.setStyleAttribute("font-family", "Rock Salt");
        txt=new Text();
    }
    
    /**
     * Permettere di ottenere tutti dati nel datatstore relativo alla homepage
     */
    private void getInfoHome(){        
        homeService.getHomeDescription("home", new AsyncCallback<String>() {
            
            public void onSuccess(String result) {
                txt.setText(result);
                layout();
            }
            
            public void onFailure(Throwable caught) {
                log.warning("Home: Errore nel callback di description");
                
            }
        });
    }
    
    public void addComponent(){
        add(name);
        add(frame);
//        add(img);
        add(txt);
//        removeAll();
//        add(c);
//        layout();
//        add(lccenter, center);
    }
}
